package GUI;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

import Client.VCPMain;

import com.toedter.calendar.JCalendar;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class OneTimeRequest extends JPanel{
	private JTextField vehicleTextField;
private JCalendar cal;
private JCalendar toCal;
private JComboBox parkingCmBox;
JComboBox startHourCmBox;
JComboBox startMinuteCmBox;
JComboBox endHourCmBox;
JComboBox endMinuteCmBox;
	public OneTimeRequest()
	{
	
		initComponent();
	}
	
	public void initComponent()
	{
		setLayout(null);
		
		JLabel lblParkingLotName = new JLabel("Parking lot name");
		lblParkingLotName.setBounds(103, 91, 124, 44);
		lblParkingLotName.setFont(new Font("Tahoma", Font.PLAIN, 17));
		add(lblParkingLotName);
		
		JLabel lblVehicleNumber = new JLabel("Vehicle number");
		lblVehicleNumber.setBounds(103, 49, 124, 21);
		lblVehicleNumber.setFont(new Font("Tahoma", Font.PLAIN, 17));
		add(lblVehicleNumber);
		
		vehicleTextField = new JTextField();
		vehicleTextField.setBounds(274, 52, 108, 31);
		add(vehicleTextField);
		vehicleTextField.setColumns(10);
		
		parkingCmBox = new JComboBox();
		parkingCmBox.setBounds(274, 106, 119, 29);
		parkingCmBox.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5", "6"}));
		add(parkingCmBox);
		
		JLabel lblDate = new JLabel("Date");
		lblDate.setBounds(34, 157, 92, 21);
		lblDate.setFont(new Font("Tahoma", Font.PLAIN, 17));
		add(lblDate);
		
		 cal=new JCalendar();
		cal.setBounds(103, 157, 325, 169);
		add(cal);
		
		
		toCal=new JCalendar();
		toCal.setBounds(490, 157, 325, 169);
		add(toCal);
		JLabel lblStartTime = new JLabel("Start time");
		lblStartTime.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblStartTime.setBounds(34, 336, 81, 31);
		add(lblStartTime);
		
		 startHourCmBox = new JComboBox();
		startHourCmBox.setBounds(153, 343, 99, 23);
		add(startHourCmBox);
		
		for(int i=0;i<24;i++)
		{
			
			if(i<10)
			{
				startHourCmBox.addItem("0"+Integer.toString(i));
			}
			else
				startHourCmBox.addItem(Integer.toString(i));
		}
		 startMinuteCmBox = new JComboBox();
		startMinuteCmBox.setBounds(291, 344, 108, 21);
		add(startMinuteCmBox);
		for(int i=0;i<60;i++)
		{
			if(i<10)
				startMinuteCmBox.addItem("0"+Integer.toString(i));	
			else
			startMinuteCmBox.addItem(Integer.toString(i));
		}
		
		JLabel label = new JLabel(":");
		label.setFont(new Font("Tahoma", Font.PLAIN, 17));
		label.setBounds(262, 347, 46, 14);
		add(label);
		
		JLabel lblFrom = new JLabel("From:");
		lblFrom.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblFrom.setBounds(34, 221, 46, 14);
		add(lblFrom);
		
		JLabel lblTo = new JLabel("To:");
		lblTo.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblTo.setBounds(438, 224, 46, 14);
		add(lblTo);
		
		JLabel lblEndTime = new JLabel("End time");
		lblEndTime.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblEndTime.setBounds(438, 347, 81, 20);
		add(lblEndTime);
		
		 endHourCmBox = new JComboBox();
		endHourCmBox.setBounds(523, 350, 92, 20);
		add(endHourCmBox);
		for(int i=0;i<24;i++)
		{
			if(i<10)
			{
				endHourCmBox.addItem("0"+Integer.toString(i));
			}
			else
			endHourCmBox.addItem(Integer.toString(i));
		}
		JLabel label_1 = new JLabel(":");
		label_1.setFont(new Font("Tahoma", Font.PLAIN, 17));
		label_1.setBounds(625, 353, 46, 14);
		add(label_1);
		
		 endMinuteCmBox = new JComboBox();
		endMinuteCmBox.setBounds(654, 350, 72, 20);
		
		add(endMinuteCmBox);
		for(int i=0;i<60;i++)
		{
			if(i<10)
				endMinuteCmBox.addItem("0"+Integer.toString(i));
			else
			endMinuteCmBox.addItem(Integer.toString(i));
		}
		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				MainScreen.cardLayot.show(MainScreen.card,"CustomerMain");
			}
		});
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 17));
		btnBack.setBounds(103, 432, 89, 31);
		add(btnBack);
		
		JButton btnExit = new JButton("Exit");
		btnExit.setFont(new Font("Tahoma", Font.PLAIN, 17));
		btnExit.setBounds(638, 432, 88, 31);
		add(btnExit);
		
		JButton btnSubmit = new JButton("Submit ");
		btnSubmit.addActionListener(new ActionListener() {  //submit button action listener
			public void actionPerformed(ActionEvent e) {
				
				if(vehicleTextField.getText().equals(""))
				{
					JOptionPane.showMessageDialog(null, "Please enter a vehicle number");
				}
				else
				{
				ArrayList <String> arrlist=new ArrayList <String>();
				arrlist.add("OneTimeRequest");
				arrlist.add(vehicleTextField.getText());
				arrlist.add((String)parkingCmBox.getSelectedItem());
				
				SimpleDateFormat format1=new SimpleDateFormat("yyyy-MM-dd");
				String formatted1=format1.format(cal.getDate());
				
				SimpleDateFormat format2=new SimpleDateFormat("yyyy-MM-dd");
				String formatted2=format2.format(toCal.getDate());
				
				arrlist.add(formatted1);
				arrlist.add(formatted2);
				
				String StartTime = (String)startHourCmBox.getSelectedItem()+ ":" +(String)startMinuteCmBox.getSelectedItem();
				arrlist.add(StartTime);
				
				String EndTime = (String)endHourCmBox.getSelectedItem()+ ":" +(String)endMinuteCmBox.getSelectedItem();
				arrlist.add(EndTime);
				int costTemp=(Integer.parseInt((String)endHourCmBox.getSelectedItem())-Integer.parseInt((String)startHourCmBox.getSelectedItem()) +1)*4; //create query to retrieve the request price
				JOptionPane.showConfirmDialog(null,"Estimated parking order price" +costTemp+"");
				int dialogRet=JOptionPane.YES_NO_OPTION;
				
				if(dialogRet==JOptionPane.YES_OPTION);
				 	VCPMain.chat.handleMessageFromGui(arrlist);
				 	
				 		
				}
			}
		});
		btnSubmit.setFont(new Font("Tahoma", Font.PLAIN, 17));
		btnSubmit.setBounds(354, 399, 108, 31);
		add(btnSubmit);
	
	}
}
